package com.situ.listener;

import javax.servlet.ServletContext;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;


@WebListener
public class OnLineNumberListener implements HttpSessionListener {

    
    public void sessionCreated(HttpSessionEvent se)  { 
         HttpSession session=se.getSession();
         ServletContext application=session.getServletContext();
         Object attribute=application.getAttribute("count");
         if(null==attribute) {
        	 application.setAttribute("count", 1);
         }else {
        	 int count=(int)attribute;
        	 application.setAttribute("count", ++count);
         }
    }

	
    public void sessionDestroyed(HttpSessionEvent se)  { 
    	HttpSession session=se.getSession();
        ServletContext application=session.getServletContext();
        int count=(int)application.getAttribute("count");
        application.setAttribute("count", --count);
    	
    }
	
}
